package com.wyvoid.forum.service.impl;

import com.wyvoid.forum.service.IForumService;
import com.wyvoid.forum.domain.Forum;
import com.wyvoid.forum.dao.IForumDAO;
import com.wyvoid.forum.Constant;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

/**
 * User: cjp
 * Date: 2007-5-16
 * Time: 11:10:11
 */
@Transactional
public class ForumService implements IForumService {
    private IForumDAO forumDAO;

    public void setForumDAO(IForumDAO forumDAO) {
        this.forumDAO = forumDAO;
    }

    public List<Forum> getForums() {
        return forumDAO.getForums();
    }

    public List<Forum> getGroupForums(long groupId) {
        return forumDAO.getGroupForums(groupId);
    }

    public List<Forum> getForums(long parentId) {
        return forumDAO.getForums(parentId);
    }

    public void createForum(Forum forum) {
        forumDAO.create(forum);
    }

    public void updateForum(Forum forum) {
        forumDAO.update(forum);
    }

    public Forum getGroupForum(long forumId) {
        Forum forum=forumDAO.getById(forumId);
        if(forum!=null&&forum.getType()== Constant.Forum.TYPE_GROUP){
            return forum;
        }else{
            return null;
        }
    }

    public Forum getForum(long forumId) {
        return forumDAO.getById(forumId);
    }

    public void closeForum(long fid) {
        Forum forum=forumDAO.getById(fid);
        if(forum!=null){
            forum.setStatus(Constant.Forum.STATUS_CLOSED);
        }
    }

    public List<Forum> getOpenedForums() {
        return forumDAO.getOpenedForums();
    }

    public List getValidForums(long parentForumId) {
        return forumDAO.getValidForums(parentForumId);
    }

    public void openForum(long fid) {
        Forum forum=forumDAO.getById(fid);
        if(forum!=null){
            forum.setStatus(Constant.Forum.STATUS_NORMAL);
        }
    }
}
